<template>
  <div class="box-age">
    <div class="title">
      <p>年龄比例</p>
      <p class="bg"></p>
    </div>
    <!-- 图表 -->
    <div ref="charts" class="age-charts"></div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import * as echarts from 'echarts'

const charts = ref()

onMounted(() => {
  const ageCharts = echarts.init(charts.value)
  ageCharts.setOption({
    tooltip: {
      trigger: 'item',
    },
    legend: {
      top: '25%', // 图例组件距离顶部
      right: 50, // 图例组件组里右侧
      orient: 'vertical', // 图例组件方向设置
      textStyle: {
        color: 'white', // 图例组件字体颜色
        fontSize: 14, // 图例组件字体大小
      },
    },
    series: [
      {
        name: '今日总数',
        type: 'pie',
        radius: ['40%', '70%'],
        center: ['40%', '55%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          // borderColor: '#fff',
          borderWidth: 2,
        },
        label: {
          show: true,
          position: 'inside',
          color: 'white',
          fontWeight: 'bold',
          formatter: (params) => Math.round(params.value) + '%',
        },
        // emphasis: {
        //   label: {
        //     show: true,
        //     fontSize: 40,
        //     fontWeight: 'bold',
        //   },
        // },
        labelLine: {
          show: true,
        },
        data: [
          { value: 16, name: '10岁及以下' },
          { value: 8, name: '10 - 18岁' },
          { value: 12, name: '18 - 30岁' },
          { value: 24, name: '30 - 40岁' },
          { value: 20, name: '40 - 60岁' },
          { value: 20, name: '60岁以上' },
        ],
      },
    ],
    grid: {
      left: 0,
      top: 0,
      right: 0,
      bottom: 0,
    },
  })
})
</script>

<style lang="scss" scoped>
.box-age {
  width: 100%;
  height: 100%;
  background: url('../../images/dataScreen-main-lb.png') no-repeat;
  background-size: 100% 100%;
  margin-bottom: 20px;
  .title {
    margin-left: 20px;
    p {
      color: white;
      font-size: 20px;
    }
    .bg {
      width: 68px;
      height: 7px;
      background: url('../../images/dataScreen-title.png') no-repeat;
      background-size: 100% 100%;
      margin-top: 10px;
    }
  }
  .age-charts {
    height: 250px;
  }
}
</style>
